package com.boxue.bxaiagents.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author: [dongliu]
 * @createTime: [2025/6/11 9:33]
 * @Description: [实现初始化向量数据库并保存文档]
 * @version: [v1.0]
 */
@Configuration
public class LoveAppVectorStoreConfig {
    @Resource
    private LoveAppDocumentLoader loveAppDocumentLoader;

    @Bean
    VectorStore loveAppVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel).build();

        // 加载文档
        List<Document> documents = loveAppDocumentLoader.loadDocuments();
        simpleVectorStore.add(documents);
        return simpleVectorStore;
    }
}
